package question5;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Commodity commodity1 = new Commodity("笔记本","g10000",10000);
        Commodity commodity2 = new Commodity("手机","g10001",5000);
        Commodity commodity3 = new Commodity("苹果","g20000",50);
        Commodity commodity4 = new Commodity("平板","g20001",3000);
        Commodity commodity5 = new Commodity("自行车","g30000",1500);
        ArrayList<Commodity> commodities = new ArrayList<>(List.of(commodity1,commodity2,commodity3,commodity4,commodity5));
        System.out.println("=======商品列表=======");
        for (Commodity commodity : commodities) {
            System.out.print(commodity.getID()+"  ");
        }
        System.out.println("\r");
        for (Commodity commodity : commodities) {
            System.out.print(commodity.getName()+"    ");
        }
        System.out.println("\r");
        ArrayList<String> list = new ArrayList<>();
        Scanner sc=new Scanner(System.in);
        while (true) {
            System.out.println("输入商品ID,结束请按0");
            String s=sc.next();
            if (!s.equals("0")){
            list.add(s);
            }
            else break;
        }
        System.out.println("=======添加商品=======");
        for (String s : list) {
            for (Commodity commodity : commodities) {
                if (commodity.getID().equals(s)){
                    System.out.println("加入"+commodity.getName()+"成功");
                }
            }
        }
        System.out.println("=======打印商品=======");
        System.out.println("您选购的商品为：");
        int sum=0;
        for (String s : list) {
            for (Commodity commodity : commodities) {
                if (commodity.getID().equals(s)){
                    System.out.println(commodity.getID()+commodity.getName()+commodity.getPrice());
                    sum+=commodity.getPrice();
                }
            }
        }
        System.out.println("--------------");
        System.out.println("原  价为："+sum);
        //System.out.println("折后价为："+sum);
    }
}
